

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store;
using JTC.MiniCommerce.Store.Web.Controls;
using SubSonic.Utilities;

namespace JTC.MiniCommerce.Web.admin.controls.order {
  public partial class transaction : AdminControl {
  
    #region Member Variables
    
    private int orderId = 0;
    private string view = string.Empty;

    #endregion
    
    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        orderId = Utility.GetIntParameter("orderId");
        view = Utility.GetParameter("view");
        if(orderId > 0 && view == "t") {
          SetTransactionProperties();
          TransactionCollection transactionCollection = new TransactionController().FetchByOrderId(orderId);
          rptrTransactions.DataSource = transactionCollection;
          rptrTransactions.ItemDataBound += new RepeaterItemEventHandler(rptrTransactions_ItemDataBound);
          rptrTransactions.DataBind();
        }
      }
      catch(Exception ex) {
        Logger.Error(typeof(transaction).Name + ".Page_Load", ex);
        base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    /// <summary>
    /// Handles the ItemDataBound event of the rptrTransactions control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param>
    void rptrTransactions_ItemDataBound(object sender, RepeaterItemEventArgs e) {
      if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        Label lblTransactionId = e.Item.FindControl("lblTransactionId") as Label;
        if(lblTransactionId != null) {
          LocalizationUtility.AddLabelText(lblTransactionId);
        }
        Label lblTransactionType = e.Item.FindControl("lblTransactionType") as Label;
        if(lblTransactionType != null) {
          LocalizationUtility.AddLabelText(lblTransactionType);
        }
        Label lblPaymentMethod = e.Item.FindControl("lblPaymentMethod") as Label;
        if(lblPaymentMethod != null) {
          LocalizationUtility.AddLabelText(lblPaymentMethod);
        }
        Label lblGatewayName = e.Item.FindControl("lblGatewayName") as Label;
        if(lblGatewayName != null) {
          LocalizationUtility.AddLabelText(lblGatewayName);
        }
        Label lblGatewayResponse = e.Item.FindControl("lblGatewayResponse") as Label;
        if(lblGatewayResponse != null) {
          LocalizationUtility.AddLabelText(lblGatewayResponse);
        }
        Label lblGatewayTransactionId = e.Item.FindControl("lblGatewayTransactionId") as Label;
        if(lblGatewayTransactionId != null) {
          LocalizationUtility.AddLabelText(lblGatewayTransactionId);
        }
        Label lblAVSCode = e.Item.FindControl("lblAVSCode") as Label;
        if(lblAVSCode != null) {
          LocalizationUtility.AddLabelText(lblAVSCode);
        }
        Label lblCVV2Code = e.Item.FindControl("lblCVV2Code") as Label;
        if(lblCVV2Code != null) {
          LocalizationUtility.AddLabelText(lblCVV2Code);
        }
        Label lblGrossAmount = e.Item.FindControl("lblGrossAmount") as Label;
        if(lblGrossAmount != null) {
          LocalizationUtility.AddLabelText(lblGrossAmount);
        }
        Label lblNetAmount = e.Item.FindControl("lblNetAmount") as Label;
        if(lblNetAmount != null) {
          LocalizationUtility.AddLabelText(lblNetAmount);
        }
        Label lblFeeAmount = e.Item.FindControl("lblFeeAmount") as Label;
        if(lblFeeAmount != null) {
          LocalizationUtility.AddLabelText(lblFeeAmount);
        }
        Label lblTransactionDate = e.Item.FindControl("lblTransactionDate") as Label;
        if(lblTransactionDate != null) {
          LocalizationUtility.AddLabelText(lblTransactionDate);
        }
        Label lblGatewayErrors = e.Item.FindControl("lblGatewayErrors") as Label;
        if(lblGatewayErrors != null) {
          LocalizationUtility.AddLabelText(lblGatewayErrors);
        }
        
      }
    }

    #endregion
    
    #region Methods
    
    #region Protected

    /// <summary>
    /// Gets the formatted amount.
    /// </summary>
    /// <param name="amount">The amount.</param>
    /// <returns></returns>
    protected string GetFormattedAmount(string amount) {
      return StoreUtility.GetFormattedAmount(amount, true);
    }
    
    #endregion
    
    #region Private

    /// <summary>
    /// Sets the transaction properties.
    /// </summary>
    private void SetTransactionProperties() {
    }

    #endregion
    
    #endregion
    
  }
}